package com.gongpingjialoan.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.gongpingjialoan.R;
import com.gongpingjialoan.api.Piont;
import com.gongpingjialoan.manage.PointRecordManage;

/**
 * Created by Administrator on 2016/11/24.
 */
public class SellSameCarDialog extends Dialog implements View.OnClickListener {

    private Context context;

    private ISellSameCar mISellSameCar;

    private TextView mTextView;

    private Button refresh_btn, sellcar_btn;

    private String msg;

    private boolean isPrivate = false;

    public SellSameCarDialog(Context context,String msg ,  ISellSameCar ISellSameCar , boolean isPrivate) {
        super(context, R.style.dialogs);
        this.context = context;
        this.mISellSameCar = ISellSameCar;
        this.msg = msg;
        this.isPrivate = isPrivate;
    }


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.sellcar_same_layout);
       // setCanceledOnTouchOutside(false);
        refresh_btn = (Button) findViewById(R.id.refresh_btn);
        sellcar_btn = (Button) findViewById(R.id.yes_btn);
        mTextView = (TextView)findViewById(R.id.tips_txt);
        mTextView.setText(msg);
        refresh_btn.setOnClickListener(this);
        sellcar_btn.setOnClickListener(this);
        if(isPrivate){
            refresh_btn.setVisibility(View.VISIBLE);
            findViewById(R.id.line).setVisibility(View.VISIBLE);
        }else{
            sellcar_btn.setBackgroundResource(R.drawable.dialog_all_button_bg);
        }
    }

    @Override
    public void onClick(View v) {
        if (v == refresh_btn) {
            if (mISellSameCar != null) {
                mISellSameCar.refresh();
                mDismiss();
            }
        } else if (v == sellcar_btn) {
            if (mISellSameCar != null) {
                mISellSameCar.sellSmaeCar();
                mDismiss();
            }
        }
    }

    private void mDismiss(){
        PointRecordManage.getInstance().addPoint(context, Piont.SellCarDuplicateAlertCancel);
        dismiss();
    }

    public interface ISellSameCar {
        public void sellSmaeCar();

        public void refresh();
    }
}
